package com.qf.test.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;

@Controller
public class FileController {
    @RequestMapping("/show")
    public void show(String fileName, HttpServletResponse response)throws Exception{
        String path = "C:\\Users\\甘学成\\Desktop\\images\\"+fileName;
        FileInputStream fis = new FileInputStream(new File(path));
        ServletOutputStream outputStream = response.getOutputStream();
        byte[] buffer = new byte[1024];
        int len;
        while ((len = fis.read(buffer)) != -1){
            outputStream.write(buffer, 0, len);
        }
        outputStream.flush();
        outputStream.close();
        fis.close();
    }
}
